const path = require('path')
// 文档地址：https://github.com/gsoft-inc/craco/blob/master/packages/craco/README.md#configuration
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin')
const { whenProd, getPlugin, pluginByName } = require('@craco/craco')

module.exports = {
  // webpack 配置
  webpack: {
    // 配置别名
    alias: {
      // 约定：使用 @ 表示 src 文件所在路径
      '@': path.resolve(__dirname, 'src')
    },
    configure: webpackConfig => {
      // 修改webpack配置
      whenProd(() => {
        // 配置webapck排除项
        webpackConfig.externals = {
          // key:val   key是包名； val是改包cdn资源在全局的变量名
          // 'react': 'React',
          // 'react-dom': 'ReactDOM',
          // 'redux': 'Redux',
        }
        const { isFound, match } = getPlugin(webpackConfig, pluginByName('HtmlWebpackPlugin'))
        if (isFound) {
          // 配置CDN资源
          match.userOptions.cdn = {  
            js: [
              // 'https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.production.min.js',
              // 'https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js',
              // 'https://cdn.bootcdn.net/ajax/libs/redux/4.1.2/redux.min.js'
            ]  
          }
        }
      })
      return webpackConfig;
    },
    plugins: {
      add: [new AntdDayjsWebpackPlugin()]
    },
  },
  
}